$(function () {
      let form = layui.form
      form.verify({
            nickname: [
                  /^[\S]{1,10}$/,
                  '昵称的长度为1-10个字符!'
            ]
      })
      // 需求:渲染用户信息
      initUserIfo()
})
function initUserIfo() {
      axios({
            method: 'GET',
            url: '/my/userinfo'
      }).then(res => {
            if (res.data.status !== 0) {
                  return layer.msg(res.data.message)
            }
            layui.form.val('formUsweInfo', res.data.data)
      })
}
$('#btnReset').on('click', function (e) {
      e.preventDefault()
      initUserIfo()
})
$('form').on('submit', function (e) {
      e.preventDefault()
      axios({
            url: '/my/userinfo',
            method: 'POST',
            data: $(this).serialize(),
      }).then(res => {
            //成功回调
            // console.log(res)
            if (res.data.status != 0) {
                  return layer.msg(res.data.message)
            }
            layer.msg("恭喜您，修改用户信息成功！")
            window.parent.getUserInfo()
      });
})